package controllers

import (
	"pfl/db"
	"pfl/models"

	"github.com/astaxie/beego"
)

type PrevloginController struct {
	beego.Controller
}

func (this *PrevloginController) Get() {
	this.TplName = "prev_login.html"
}

func (this *PrevloginController) Post() {
	username := this.GetString("username")
	password := this.GetString("password")

	info := models.Prevuser{}
	ok, err := db.Mysql.Where("Username=?", username).Get(&info)
	if !ok || err != nil {
		this.Ctx.WriteString("用户名或密码错误")
		return
	}
	if info.Password != password {
		this.Ctx.WriteString("密码错误")
		return
	} else {
		this.SetSession("username", info.Username)
		//this.Ctx.WriteString("登陆成功")
		this.Redirect("/", 302)
	}
}
